package com.tjp.eight.ui.fragment.sub;

import com.tjp.eight.AllRetrofit;
import com.tjp.eight.base.BasePresenterImpl;
import com.tjp.eight.constant.UrlConstant;
import com.tjp.eight.net.NetCallBack;
import com.tjp.eight.net.SubscribeCallBack;

import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
 * Created by Administrator on 2017/2/17.
 */
public class SubPresenter extends BasePresenterImpl<SubView> {
    SubService service = AllRetrofit.getRetrofit(UrlConstant.BaseUrl).create(SubService.class);

    public SubPresenter(SubView subView) {
        attachView(subView);
    }

    public void loadMyData(String json) {
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), json);
        addSubscription(service.loadData(requestBody), new SubscribeCallBack<>(new NetCallBack<SubItemModel>() {
            @Override
            public void onSuccess(SubItemModel model) {
                view.loadMyData(model);
            }

            @Override
            public void onFails(int code, String msg) {
                view.loadFail(msg);
            }

            @Override
            public void onCompleted() {

            }
        }));
    }
    public void loadMoreData(String json) {
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), json);
        addSubscription(service.loadData(requestBody), new SubscribeCallBack<>(new NetCallBack<SubItemModel>() {
            @Override
            public void onSuccess(SubItemModel model) {
                view.loadMoreData(model);
            }

            @Override
            public void onFails(int code, String msg) {
                view.loadFail(msg);
            }

            @Override
            public void onCompleted() {

            }
        }));
    }
    public void sub(String subJson) {
        RequestBody req = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), subJson);
        addSubscription(service.sub(req), new SubscribeCallBack<>(new NetCallBack<SubResultModel>() {
            @Override
            public void onSuccess(SubResultModel model) {
                view.subSuccess(model);
            }

            @Override
            public void onFails(int code, String msg) {
                view.loadFail(msg);
            }

            @Override
            public void onCompleted() {

            }
        }));
    }
    public void subMore(String subJson) {
        RequestBody req = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), subJson);
        addSubscription(service.sub(req), new SubscribeCallBack<>(new NetCallBack<SubResultModel>() {
            @Override
            public void onSuccess(SubResultModel model) {
                view.subMoreSuccess(model);
            }

            @Override
            public void onFails(int code, String msg) {
                view.loadFail(msg);
            }

            @Override
            public void onCompleted() {

            }
        }));
    }
}
